<?php
require("includes/basic.php");
$pid=$_REQUEST['pid'];
$sid=$_REQUEST['sid'];
$mid=$_REQUEST['mid'];
if(isset($_POST['pid']) && isset($_POST['sid']) && $_POST['mid'])
{
	$pid = $_POST['pid'];
	$sid = $_POST['sid'];
	$mid = $_POST['mid'];
	$delete = mysql_query("DELETE u, up, upc, ut, utp, utpd
FROM task_master AS u
LEFT JOIN phase_module AS up ON u.project_id= up.project_id and u.phase_id= up.phase_id and u.module_id = u.module_id
LEFT JOIN task_assigned_to AS upc ON u.task_id = upc.task_id
LEFT JOIN task_status AS ut ON ut.task_id = u.task_id
LEFT JOIN task_timeline AS utp ON utp.task_id = u.task_id
LEFT JOIN task_doc AS utpd ON utpd.task_id = u.task_id
where u.project_id= $pid and u.phase_id= $sid and u.module_id = $mid");
	
	//header("location:open-project.php?p=$pid");
}

$checktask = mysql_query("select * from task_master where project_id= $pid and phase_id= $sid and module_id = $mid");
$taskno = mysql_num_rows($checktask);

	?>
	<script type='text/javascript' src='js/jquery-latest.js'></script>
	<script type="text/javascript">
	$(document).ready(function()
	{
		var taskno = $('#taskno').val();		
		var proid =  $('#proid').val();
		var sid = $('#sid').val();
		var mid = $('#mid').val();
		
		if(taskno > 0)
		{
			var conf = confirm("Deleting this module will delete all the task added in this module");
			if(!conf)
			{
			window.location='open-project.php?p='+ proid;
			}
			else
			{
				dataString = "pid=" + proid + "&sid=" + sid + "&mid=" + mid;
				$.ajax
					({
						type: "POST",
						url: "delmodule.php",
						data: dataString,
						cache: false,
						success: function(html)
						{
						
						window.location='open-project.php?p='+ proid;
						} 
					});
			}
		}
		else
		{
			dataString = "pid=" + proid + "&sid=" + sid + "&mid=" + mid;
			$.ajax
				({
					type: "POST",
					url: "delmodule.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
					window.location='open-project.php?p='+ proid;
					} 
				});
		}
	
	});
	</script>
	<?php
	echo "<input type='hidden' value='$pid' id='proid'>";
	echo "<input type='hidden' value='$sid' id='sid'>";
	echo "<input type='hidden' value='$mid' id='mid'>";
	echo "<input type='hidden' value='$taskno' id='taskno'>";

?>